﻿

#region Using Statements

// System References
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;

// XNA References
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

// Internal References

#endregion


namespace Freeform.Framework.Utility
{
    /// <summary>
    /// Provides a read-only wrapper class for a Dictionary.
    /// </summary>
    /// <typeparam name="KeyType">The key type of the dictionary.</typeparam>
    /// <typeparam name="ValueType">The value type of the dictionary.</typeparam>
    public class ReadOnlyDictionary<KeyType, ValueType> : IEnumerable<ValueType> 
        where ValueType : class 
    {

        #region Members

        /// <summary>
        /// Gets or sets the base dictionary that we will provide a read only wrapper for.
        /// </summary>
        private Dictionary<KeyType, ValueType> Dictionary { get; set; }


        /// <summary>
        /// Provides the user the ability to lookup a Value indexed with a Key.
        /// </summary>
        /// <param name="Key">The key of the value to lookup.</param>
        /// <returns>A value.</returns>
        public ValueType this[KeyType Key] 
        {
            get { return Dictionary[Key]; }
        }


        /// <summary>
        /// Gets the number of key, value pairs in the dictionary.
        /// </summary>
        public Int32 Count { get { return Dictionary.Count; } }

        #endregion


        #region Init

        /// <summary>
        /// Creates a read-only wrapper class for a given Dictionary.  The wrapper will stay up-to-date with the Dictionary
        /// so there is no need to keep creating new wrappers.  Values from the dictionary are found by using the index operator:
        /// ValueType myValue = myReadOnlyDictionary[myKey];
        /// </summary>
        /// <param name="Base">The dictionary to wrap in read-only mode.</param>
        public ReadOnlyDictionary(Dictionary<KeyType, ValueType> Base)
        {
            if (Base == null) throw new Exception("Cannot create a ReadOnlyDictionary from a null source Dictionary!");

            Dictionary = Base;
        }

        #endregion


        #region IEnumerable

        /// <summary>
        /// Allows the foreach command to be used on the data structure.
        /// </summary>
        /// <returns>An enumerator.</returns>
        public IEnumerator<ValueType> GetEnumerator()
        {
            return Dictionary.Values.GetEnumerator();
        }


        /// <summary>
        /// Allows the foreach command to be used on the data structure.
        /// </summary>
        /// <returns>An enumerator.</returns>
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return Dictionary.Values.GetEnumerator();
        }

        #endregion


        #region Utility


        #endregion

    }
}